package com.bnp.reporting.java8.collection;

import com.bnp.reporting.java8.entity.Person;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

/**
 * Sequential Stream
 * Created by Adib on 10/11/14.
 * Working with a data as whole, instead of doing with each item individually
 */
public class ParallelStream {

    public static void main(String[] args) {

        List<Person> people = new ArrayList<Person>();
        people.add(new Person(34, "Adib"));
        people.add(new Person(30, "Neeraj"));
        people.add(new Person(37, "HongFei"));

        Predicate<Person> predicate = (p) -> p.getAge() > 35;

        displayPeople(people, predicate);

    }

    private static void displayPeople(List<Person> people, Predicate<Person> predicate) {
        System.out.println("Selected:");
        /*people.forEach(p -> {
            if(predicate.test(p)){
                System.out.println(p.getName());
            }
        });*/

        people.parallelStream()
                .filter(predicate)
                .forEach(p -> System.out.println(p.getName()));
    }
}
